package com.cskaoyan.controller.extendController;

import com.cskaoyan.exception.GoodsIdNonexistentException;
import com.cskaoyan.model.bean.GrouponRules;
import com.cskaoyan.model.bo.extend.GrouponBo;
import com.cskaoyan.model.bo.extend.GrouponRulesBo;
import com.cskaoyan.model.vo.extend.BaseRespVo;
import com.cskaoyan.model.vo.extend.GrouponRulesVo;
import com.cskaoyan.model.vo.extend.GrouponVo;
import com.cskaoyan.service.GrouponService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：Chunk
 * @Description:
 * @Date Created in 12:26 2021/4/10
 */
@RestController
@RequestMapping("admin/groupon")
public class GrouponController {
    @Autowired
    GrouponService grouponService;

    @RequestMapping("list")
    @RequiresPermissions("admin:groupon:list")
    public BaseRespVo grouponList(GrouponRulesBo grouponRulesBo){
        GrouponRulesVo grouponRulesVo = grouponService.grouponList(grouponRulesBo);
        return BaseRespVo.ok(grouponRulesVo);
    }
    @RequestMapping("listRecord")
    @RequiresPermissions("admin:groupon:listRecord")
    public BaseRespVo grouponListRecord(GrouponBo grouponBo){
        GrouponVo grouponVo = grouponService.grouponListRecord(grouponBo);
        return BaseRespVo.ok(grouponVo);
    }
    @RequestMapping("create")
    @RequiresPermissions("admin:groupon:create")
    public BaseRespVo grouponCreate(@RequestBody GrouponRules grouponRules) throws GoodsIdNonexistentException {
        GrouponRules grouponRulesVo = grouponService.grouponCreate(grouponRules);
        return BaseRespVo.ok(grouponRulesVo);
    }
    @RequestMapping("update")
    @RequiresPermissions("admin:groupon:update")
    public BaseRespVo grouponUpdate(@RequestBody GrouponRules grouponRules) throws GoodsIdNonexistentException {
        GrouponRules grouponRulesVo = grouponService.grouponUpdate(grouponRules);
        return BaseRespVo.ok(grouponRulesVo);
    }
    @RequestMapping("delete")
    @RequiresPermissions("admin:groupon:delete")
    public BaseRespVo grouponDelete(@RequestBody GrouponRules grouponRules){
        grouponService.grouponDelete(grouponRules);
        return BaseRespVo.ok();
    }
}
